package com.kjtpay.design_pattern.proxy;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.kjtpay.design_pattern.R;
import com.kjtpay.design_pattern.decorator.DecoratorActivity;

public class ProxyActivity extends AppCompatActivity {

    SchoolGirl mm;
    Proxy proxy;
    EditText editTextName;
    TextView textViewWhatToDo;

    public static void launch(Context context) {
        if (null != context) {
            Intent intent = new Intent();
            intent.setClass(context, ProxyActivity.class);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_proxy);
        setTitle("代理模式");

        mm = new SchoolGirl();
        proxy = new Proxy(mm);
        editTextName = (EditText)findViewById(R.id.editTextName);
        textViewWhatToDo = (TextView)findViewById(R.id.textViewWhatToDo);
    }

    public void onDollClick(View view) {
        mm.Name = editTextName.getText().toString();
        proxy.GiveDolls();
        textViewWhatToDo.setText(proxy.GetResult());
    }

    public void onFlowerClick(View view) {
        mm.Name = editTextName.getText().toString();
        proxy.GiveFlowers();
        textViewWhatToDo.setText(proxy.GetResult());
    }

    public void onChocolateClick(View view) {
        mm.Name = editTextName.getText().toString();
        proxy.GiveChocolate();
        textViewWhatToDo.setText(proxy.GetResult());
    }
}